#!/bin/bash

dir=$1

if [ -z "$dir" ]; then
    echo "$0 <dir or file>"
    exit 1
fi

files=$(mktemp)

ls "$dir" > $files
readarray -t fs < "$files"

for i in $(seq 0 1 $((${#fs[@]} - 1)))
do
  INPUT=${fs[$i]}
  O=${INPUT//rmvb/mkv}
  echo "Converting $INPUT ..."
  ffmpeg -hwaccel cuda -i "$dir/$INPUT" -c:a aac -c:v h264 -b:v 800K -f matroska "$dir/${O}"
done

rm -f $files

